package apii.servlet.prof;

import java.io.*;
import java.sql.*;

import apii.server.*;

public class Test {
	public static void main(String[] args) throws SQLException, IOException {
		try (Connection c1 = ServerThings.getThings().getConnection();
				Statement st1 = c1.createStatement();
				Connection c2 = ServerThings.getThings().getConnection();
				Statement st2 = c2.createStatement();
				InputStreamReader isr = new InputStreamReader(System.in);
				BufferedReader br = new BufferedReader(isr);) {
			String s;
			while ((s = br.readLine()) != null) {
				try {
					String[] ss = s.split(" ", 2);
					Statement st = ss[0].equals("1") ? st1 : st2;
					if (st.execute(ss[1])) {
						ResultSet rs = st.getResultSet();
						while (rs.next()) {
							for (int i = 1; i <= rs.getMetaData()
									.getColumnCount(); ++i)
								System.out.print(rs.getObject(i) + "\t");
							System.out.println();
						}
					}
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}
}
